var orderTableShip=null;
/**
 * 页面初始化
 */
$(function () {
    
});

function showShippingTab(){
    //后台ajax
//      $.ajax({
//          type: "GET",
//          url: "/order/getOrderInfo.action?orderId=" + $('#myid', window.parent.document).val(),
//          contentType: "application/json;charset=utf-8",
//          dataType: "json",
//          async: true,//同步
//          success: function (data) {
//              if (data.result == "success") {
//                  $("#labelCons").html("收货人："+data.data.cons);
//                  $("#labelConsTel").html("固定电话："+data.data.consTel);
//                  $("#labelConsMobile").html("手机："+data.data.consMobile);
//                  $("#labelConsAddr").html("收货地址："+data.data.consAddr);
//                  $("#labelConsPostCode").html("邮编："+data.data.consPostCode);
//              } else {
//                  window.top.window.showModalAlert(data.msg);
//              }
//          },
//          error: function (XMLHttpRequest, textStatus) {
//              if (XMLHttpRequest.status == 500) {
//                  var result = eval("(" + XMLHttpRequest.responseText + ")");
//                  alert(result.errorObject.errorText);
//              }
//          }
//      });
      
      //发货信息
      if (orderTableShip==null){
          orderTableShip = $('#orderTableShip').DataTable({
              "autoWidth": false,
              "processing": true,
              "serverSide": true,
              "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
              "dom": '<"bottom"rtflp>',
              "searching": false,
              "pagingType": "full_numbers",
              "deferRender": true,
              "ajax": {
                  "url": "/shiporder/getShiporderListByOrderIdNoStorType.action?orderId="+$('#myid', window.parent.document).val()
                  },
              "tableTools": {
                  "sRowSelect": "bootstrap"
              },
              "columns": [
                  {"data": "cancelStatus", 
                      "render": function ( data, type, row, meta ) {console.log(row.cancelStatus);
                          if (row.cancelStatus == "n") {
                              return "未取消";
                          } else if (row.cancelStatus == "r") {
                              return "申请取消";
                          } else if (row.cancelStatus == "f") {
                              return "取消失败";
                          } else if (row.cancelStatus == "y") {
                              return "取消成功";
                          } 
                      }
                  },
                  {"data": "lockStatus", 
                      "render": function ( data, type, row, meta ) {
                          if (row.lockStatus == "y") {
                              return "锁定";
                          } else {
                              return "未锁定";
                          }
                      }
                  },
                  {"data": "shiporderStatus",
                      "render": function ( data, type, row, meta ) {
                          if (row.shiporderStatus == "waitSendOutGoods") {
                              return "待发货";
                          }else if (row.shiporderStatus == "sendingOutGoods") {
                              return "发货中";
                          }
                          else if (row.shiporderStatus == "shiped") {
                              return "已系统发货";
                          }
                          else if (row.shiporderStatus == "consigned") {
                              return "已平台发货";
                          }
                          else if (row.shiporderStatus == "canceled") {
                              return "已取消";
                          }
                          else {
                              return "&nbsp;";
                          }
                      }
                  },
                  {"data": "shiporderCode"},
                  {"data": "wmsShiporderCode"},
                  {"data": "lgstName"},
                  {"data": "lgstNo"},
                  {"data": "createTime"},
                  {"data": "shipTime"},
                  {"data": "consignTime"},
                  {"data": "operationOrder", "orderable": false},
                  {"data": "cancelRemark", "visible": false},
                  {"data": "storCode", "visible": false},
                  {"data": "entId", "visible": false},
                  {"data": "storId", "visible": false},
                  {"data": "prjId", "visible": false},
                  {"data": "sourceId", "visible": false},
                  {"data": "sourceType", "visible": false}
                  ],
                  "columnDefs": [
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[2]},
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[3]},
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[4]},
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[5]},
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[6]},
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[7]},
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[8]},
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[9]},
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[10]},
                      {"className": "truncate-text tooltip-column-detail-5", "targets":[11]}
                  ],
                  "order": [[1, "asc"]]
          });
          
       // 文字过长截断显示悬浮框
          $("#orderTableShip").tooltip({
              selector: ".tooltip-column-detail-5",
              container: "body",
              title: function() {
                  if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                      return $(this).text();
                  }
              }
          });
      } else {
          orderTableShip.draw();
      }
}

//取消发货单
function operationCancel(btnCancel,shiporderStatus) {
    var trNode = btnCancel.parentNode.parentNode;
    var rowData = null;

    rowData = orderTableShip.row(trNode).data();
    var data = {
        "shiporderId": encodeURI($(btnCancel).attr("shiporderId")),
        "shiporderStatus": encodeURI(shiporderStatus),
        "sourceType": encodeURI(rowData.sourceType),
        "storCode": encodeURI(rowData.storCode),
        "qmOwnercode": encodeURI(rowData.qmOwnercode),
        "wmsShiporderCode": encodeURI(rowData.wmsShiporderCode),
        "entId": encodeURI(rowData.entId),
        "storId": encodeURI(rowData.storId),
        "prjId": encodeURI(rowData.prjId),
        "sourceId": encodeURI(rowData.sourceId)
    }
    
    var flg = '0';
    
    $.ajax({
        type: "POST",
        url: "/shiporder/cancelShiporder.action",
        data: JSON.stringify(data),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (json) {
            if (json.result=="success") {
                window.top.window.showScoMessage('ok', json.data);
                $('#reloadBtn', window.parent.document).click();
//                orderTableShip.draw();
            } else {
                window.top.window.showModalAlert(json.msg);
            }
        }
    });
    
//    if (flg=="1" && "waitSendOutGoods" == shiporderStatus){
//        //在待发货的时候，返回成功标识后，订单的状态，订单的发货中数量要进行改变
//        $.ajax({
//            type: "POST",
//            url: "/order/cancelShiporder.action",
//            data: JSON.stringify(data),
//            contentType: "application/json;charset=utf-8",
//            dataType: "json",
//            success: function (json) {
//                if (json.result=="success") {
//                    window.top.window.showScoMessage('ok', json.data);
//                    orderTableShip.draw();
//                } else {
//                    window.top.window.showModalAlert(json.msg);
//                }
//            }
//        });
//    }
}